home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / cache.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  3.7 KB  |  113 lines

  1.  
  2. /****** cache.h *******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.1                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date: July 29, 1986          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. #define ECACHE 0    /* Implement expression cache if defined */
  24.  
  25. #if ECACHE
  26.  
  27. /*
  28.  * The expression cache can be turned on selectively for expressions with
  29.  * primitive functions, user-defined functions, or PFOs.
  30.  *
  31.  * Cache[i].Enable = 0/1 to turn off/on cache for expression type i in [0..2]. 
  32.  */
  33. #define CachePrim  0
  34. #define CacheUser  1
  35. #define CachePFO   2
  36. #define CacheTotal 3
  37.  
  38. typedef struct {
  39.    boolean Enable;
  40.    int Looks;        /* Number of looks into cache */
  41.    int Hits;        /* Number of successful looks */
  42.    int Evictions;    /* Number of evictions          */
  43.    char *Name;        /* "Prim", "User", "PFO", etc.*/    
  44. } CacheRec;
  45.  
  46. extern CacheRec Cache[];
  47.  
  48. #if DEBUG
  49. extern void PrintCache ();
  50. #endif
  51.  
  52. /*
  53.  * The expression cache is implemented as a hash table.  It
  54.  * associates outputs with <input,function> pairs.
  55.  */
  56.  
  57. #define CACHE_SIZE 1024 /* Must be power of 2 */
  58.  
  59. /*
  60.  * EC_Fun.Tag = BOTTOM iff that cache entry is empty
  61.  */
  62. typedef struct {
  63.    Object EC_In, EC_Out;
  64.    NodePtr EC_Fun;
  65. } CacheEntry;
  66.  
  67. extern CacheEntry ECache[];
  68. extern int HashOb ();
  69. extern void ShowCache (); /* Show cache statistics                */
  70.  
  71. /*
  72.  * CheckCache
  73.  *
  74.  * Parameter
  75.  *      T = &Cache[i] where i is type of function to be cached.
  76.  *    A = call to "apply" with appropriate arguments.
  77.  */
  78. #define CheckCache(T,A)                            \
  79.    if ((T)->Enable) {                            \
  80.       CacheEntry *C;                            \
  81.       extern int TraceDepth;                        \
  82.                                     \
  83.       (T)->Looks++;                            \
  84.       C = &ECache [(HashOb(InOut) + (long) F->Node) * 0x9B & CACHE_SIZE-1]; \
  85.       if (ApplyFun == C->EC_Fun && ObEqual (InOut,&C->EC_In)) {        \
  86.      if (Debug & DebugCache) PrintCache ("Hit!",C);            \
  87.      (T)->Hits++;                            \
  88.      if (Trace|SaveTrace) printf ("IBID\n");            \
  89.      RepObject (InOut,&C->EC_Out);                    \
  90.       } else {                                \
  91.      if (C->EC_Fun != NULL) {                    \
  92.         (T)->Evictions++;                        \
  93.         if (Debug & DebugCache) PrintCache ("Evict",C);        \
  94.      }                                \
  95.      C->EC_Fun = NULL;                        \
  96.      RepObject (&C->EC_In,InOut);                    \
  97.      {A;}                                \
  98.      C->EC_Fun = F->Node;                        \
  99.      RepObject (&C->EC_Out,InOut);                    \
  100.      if (Debug & DebugCache) PrintCache ("Load",C);            \
  101.       }                                    \
  102.    } else {A;}
  103.  
  104. #else
  105.  
  106. #define CheckCache(T,A) {A;}
  107. #define ClearCache()
  108.  
  109. #endif
  110.  
  111. /***************************** end of cache.h ****************************/
  112.  
  113.